package com.kebabeaters.nakebab.client.ui.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasAllMouseHandlers;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.Widget;
import com.gwtplatform.mvp.client.ViewImpl;
import com.kebabeaters.nakebab.client.presenter.ContentPresenter;
import com.kebabeaters.nakebab.client.presenter.ContentPresenter.Display;

public class ContentView extends ViewImpl implements Display {

	public interface Binder extends UiBinder<Widget, ContentView> {
	}

	private final Binder uiBinder = GWT.create(Binder.class);

	private Widget widget;

	@UiField
	protected FlowPanel navigationPanel;
	@UiField
	protected FocusPanel contentPanel;

	public ContentView() {
		widget = uiBinder.createAndBindUi(this);
	}

	@Override
	public Widget asWidget() {
		return widget;
	}

	@Override
	public void setInSlot(Object slot, Widget content) {

		if (slot == ContentPresenter.TYPE_Content) {
			setContentInSlot(content, contentPanel);
		} else if (slot == ContentPresenter.TYPE_Navigation) {
			setContentInSlot(content, navigationPanel);
		} else {
			super.setInSlot(slot, content);
		}
	}

	private void setContentInSlot(Widget content, Panel slot) {
		slot.clear();

		if (content != null)
			slot.add(content);
	}

	@Override
	public HasAllMouseHandlers getAllMouseHandlers() {
		return contentPanel;
	}

}
